package com.gmall.rabbitmq.producer.controller;

import com.gmall.rabbitmq.config.RabbitMQConfig_WorkQueue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/workqueue")
public class WorkQueueController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    int index = 0;
    @GetMapping("sendMessage")
    public String sendMessage() {
        rabbitTemplate.convertAndSend(
                RabbitMQConfig_WorkQueue.Exchange_Direct_2109A,
                RabbitMQConfig_WorkQueue.ROUTING_KEY,
                "Hello World " + index++);
        return "success";
    }

    @GetMapping("sendMessage1")
    public String sendMessage1() {
        rabbitTemplate.convertAndSend(
                RabbitMQConfig_WorkQueue.Exchange_Direct_2109A,
                "12121313",
                "Hello World " + index++);
        return "success";
    }
}
